package com.mystnihon.freeremote.ui;

import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;

import com.actionbarsherlock.app.SherlockFragmentActivity;

public abstract class DefaultObserverSherlockFragmentActivity extends SherlockFragmentActivity implements Observer {

	protected ArrayList<Observable> mLstObservable;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		mLstObservable = new ArrayList<Observable>();
	}

	protected void addObservers() {
		for (final Observable obs : mLstObservable) {
			obs.addObserver(this);
		}
	}

	protected void removeObservers() {
		for (final Observable obs : mLstObservable) {
			obs.deleteObserver(this);
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		addObservers();
	}

	@Override
	protected void onPause() {
		super.onPause();
		removeObservers();
	}

	protected void putObservable(Observable obs) {
		if (!mLstObservable.contains(obs)) {
			mLstObservable.add(obs);
		}
	}
}
